package com.ordertracker.security;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.ws.rs.ext.Provider;

import org.springframework.stereotype.Component;

import com.sun.jersey.api.container.filter.RolesAllowedResourceFilterFactory;
import com.sun.jersey.api.model.AbstractMethod;
import com.sun.jersey.spi.container.ResourceFilter;

/**
 * Description of class.
 * Created 1/9/13 4:20 PM
 *
 * @author andrey.rodin@playtech.com
 */

@Component
@Provider
public class ResourceFilterFactory extends RolesAllowedResourceFilterFactory {

    @Resource
    private SecurityContextFilter securityContextFilter;

    @Override
    public List<ResourceFilter> create(AbstractMethod am) {
        List<ResourceFilter> resourceFilters = super.create(am);
        if(null == resourceFilters) {
            resourceFilters = new ArrayList<ResourceFilter>();
        }

        List<ResourceFilter> filters = new ArrayList<ResourceFilter>(resourceFilters);
        filters.add(0, securityContextFilter);

        return filters;
    }
}
